//
// Created by hjie on 23-12-31.
//

#pragma once

#include "operate_define.h"
#include <thread>

struct InputFile
{
    int m_index{0};
    InputFormatContext m_input_ctx;
    PacketMessageQueue m_read_packet_queue;
    FrameMessageQueue  m_decode_frame_queue;
    int m_reach_end{false};
    AVFilterContext * m_buffer_filter_ctx{nullptr};
    int64_t m_input_time{0};
    std::thread m_thread;
};

struct AudioMix
{
    std::map<int, std::shared_ptr<InputFile>> m_input_file_map;
    AVFilterGraph   *  m_filter_graph;
    AVFilterContext *  m_buffer_sink_ctx;
    OutputFormatContext m_output_ctx;
    FrameMessageQueue  m_filter_frame_queue;
    PacketMessageQueue m_encode_packet_queue;
};

bool InitFilterGraph(AudioMix & mix_data);

bool InitInputFile(std::vector<std::string> file_vector, AudioMix & mix_data);

bool InitOutputFile(AudioMix & mix_data, AVFrame * frame);

bool FilterProcessFrame(AudioMix & mix_data, std::shared_ptr<InputFile> input, AVFrame * frame);


